/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package DAO;

import ObjetData.Commande;
import ObjetData.Utilisateur;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author julien
 */
public class DaoCommande extends DAO<Commande> {

    @Override
    public boolean delete(Commande obj) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public boolean save(Commande obj) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public Commande find(int id) {
        if (id > 0) {
            Commande cde = new Commande();
            ResultSet result = null;
            try {
                result = Connect.getConnexion().createStatement(
                        ResultSet.TYPE_SCROLL_INSENSITIVE,
                        ResultSet.CONCUR_READ_ONLY).executeQuery(
                        "SELECT id, date, id_utilisateur, status FROM APP.COMMANDE_E where id = " + id);
                if (result.first()) {
                    result.first();
                    cde.setNumero(result.getInt("id"));
                    cde.setStatus(result.getString("status"));
                    cde.setDatedeCommande(result.getDate("date"));
                    try {
                        Utilisateur client = new Utilisateur(result.getInt("id_utilisateur"));
                        cde.setClient(client);
                    } catch (Exception e) {
                    }
                }
            } catch (SQLException ex) {
                Logger.getLogger(DaoAnimal.class.getName()).log(Level.SEVERE, null, ex);
            }
            return cde;
        } else {
            throw new DaoException("Commande d'id [" + id + "] inconnue", 2);
        }
    }

    @Override
    public HashMap<Integer, Commande> getAll() {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    @Override
    public HashMap<Integer, Commande> search(String searchValue, Integer idCatValue) {
        throw new UnsupportedOperationException("Not supported yet.");
    }

    public int getNextNumero() {
        ResultSet result = null;
        int maxId = 1;
        try {
            result = Connect.getConnexion().createStatement(
                    ResultSet.TYPE_SCROLL_INSENSITIVE,
                    ResultSet.CONCUR_READ_ONLY).executeQuery(
                    "SELECT max(id) as id_max FROM APP.COMMANDE_E");
            if (result.first()) {
                result.first();
                maxId = result.getInt("max_id") + 1;
            }
        } catch (SQLException ex) {
            Logger.getLogger(DaoAnimal.class.getName()).log(Level.SEVERE, null, ex);
        }
        return maxId;
    }
}
